package org.example.auth.service;

import org.example.common.core.exception.ServiceException;
import org.example.common.core.utils.SpringUtils;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * 用户认证
 */
public interface IAuthStrategy {

    public static String BASE_NAME="AuthStrategy";

    static UserDetails authentication(UsernamePasswordAuthenticationToken authenticationToken, String grantType){
        // 授权类型和客户端id
        String beanName = grantType + BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new ServiceException("授权类型不正确!");
        }
        IAuthStrategy instance = SpringUtils.getBean(beanName);
        return instance.authentication(authenticationToken);
    }

    UserDetails authentication(UsernamePasswordAuthenticationToken authenticationToken);

}
